import {Address} from "src/constants"
import server from '../request'

function fetchCardList(payload) {
    let uri = Address + 'user/bankcard?' + server.getParams(payload)
    return server.requestPromise({uri: uri, method: 'GET'})
}

function addCard(payload) {
    let uri = Address + 'user/card/add'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})
}

function autoCreatePlan(payload) {
    let uri = Address + 'plan/make/auto'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})
}

function updatePlan(payload) {
    let uri = Address + 'plan/make/update'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})
}

function fetchProvinces(){
    let uri = Address + 'area'
    return server.requestPromise({uri: uri, method: 'GET'})
}

function fetchBankList() {
    let uri = Address + 'banks'
    return server.requestPromise({uri: uri, method: 'GET'})
}

function makeSurePlan(payload) {
    let uri = Address + 'plan/make/confirm'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})

}
function authCard(payload) {
    let uri = Address + 'channel/authentication'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})

}
function authCardConfirm(payload) {
    let uri = Address + 'channel/authentication/confirm'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})
}

function bankCardList(payload) {
    let uri = Address + 'user/bankcard?' + server.getParams(payload)

    return server.requestPromise({uri: uri, method: 'GET'})
}

function deleteBankCard(payload,id) {
    let uri = Address + 'user/bankcard/delete/' + id
    return server.requestPromise({uri: uri, method:'POST',body:payload})
}

function refreshCashcard(payload) {
    let uri = Address + 'user/change/cashcard'
    return server.requestPromise({uri: uri, method:'POST',body:payload})
}

function refreshBankcardUpdate(payload,banks_id) {
    let uri = Address + 'user/bankcard/update/' + banks_id
    return server.requestPromise({uri: uri, method:'POST',body:payload})
}

module.exports = {
    fetchCardList: fetchCardList,
    addCard: addCard,
    autoCreatePlan: autoCreatePlan,
    fetchProvinces: fetchProvinces,
    updatePlan: updatePlan,
    fetchBankList: fetchBankList,
    makeSurePlan: makeSurePlan,
    authCard: authCard,
    authCardConfirm: authCardConfirm,
    bankCardList:bankCardList,
    deleteBankCard:deleteBankCard,
    refreshCashcard:refreshCashcard,
    refreshBankcardUpdate:refreshBankcardUpdate
}
